/*
 * Authors: Brian Bousquet-Smith, Chaz Godwin
 * Project: OBDII Reader
 * Description: Project reads an OBDII and then outputs to a LCD
 * Date: May 16th, 2011
 */

#include <stdio.h>

char getobd2 (void);
int sendobd2 (char byte);
void ledon (void);
void ledoff (void);
int main (void){
	int i;
	char results[10];
	char button = -1;
	while(button==-1); //Change this to check for a button
	while(1){
		switch(button){
			case 1:	//RPM
				if(sendobd2(0x01)) return -1;
				if(sendobd2(0x0C)) return -1;
				for(i=0;i<2;i++){
					results[i] = getobd2();
				}
				double rpm = (results[0]*256+results[1])/4;
				if(rpm<0||rpm>16383.75){
					return -1;
				}
				//TODO print RPM
					break;
			case 2: //MPH
				if(sendobd2(0x01)) return -1;
				if(sendobd2(0x0D)) return -1;
				double mph = getobd2();
				if(mph<0||mph>255){
					return -1;
				}
				mph = mph*.6214;
				//TODO print MPH
				break;
			case 3: //END
				return 0;
			default:
				//TODO flash LED
				break;
		}
	}
}

char getobd2(void){
	return 0;
}

int sendobd2 (char byte){
	return 0;
}
void ledon (void){
	//TODO Set up LED to turn on
}
void ledoff (void){
	//TODO Set up LED to turn off
}


